{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from nltk.parse.stanford import StanfordParser\n",
    "import numpy as np\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.13.1'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Building a parse tree from a sentence "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<nltk.parse.stanford.StanfordParser at 0x258638fe390>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentence = 'The quick brown fox jumps over the lazy dog'\n",
    "\n",
    "# create parser object\n",
    "scp = StanfordParser(path_to_jar='E:/stanford/stanford-parser-full-2015-04-20/stanford-parser.jar',\n",
    "                   path_to_models_jar='E:/stanford/stanford-parser-full-2015-04-20/stanford-parser-3.5.2-models.jar')\n",
    "\n",
    "scp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(ROOT\n",
      "  (NP\n",
      "    (NP (DT The) (JJ quick) (JJ brown) (NN fox))\n",
      "    (NP\n",
      "      (NP (NNS jumps))\n",
      "      (PP (IN over) (NP (DT the) (JJ lazy) (NN dog))))))\n"
     ]
    }
   ],
   "source": [
    "# get parse tree\n",
    "result = list(scp.raw_parse(sentence)) \n",
    "tree = result[0]\n",
    "\n",
    "# print the constituency parse tree\n",
    "print(tree) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# visualize constituency parse tree\n",
    "tree.draw() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAADPCAYAAADf5VdnAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\njwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABPQSURBVHhe7d3Ncas8GIbhVOV13InTiXdpwNvs\nPZMK4hoy2XnrGk4HHAQSvAjxKyEE3ItrvmMQIMnwPgbnG7/9+/cvAwBgLoIEAOCFIAEAeCFIAABe\nCBIAgBeCBBH8ZpfzNXt7dzjfs+8x7T8e2V+r3di2r+zzw2ojXX9FWwBTESSIoCdIFFn4n4/s1Bk6\nt+zzKfY7ui1BAiyJIEEEOkhadx/2clHwreL+fdXLq9CZ0lYw4dN5hwNgKoIEEYwMkt4ir4PD3GlM\naSvXESRAcAQJIhh4tGXuKH7uzdcWc6dx+ZnYVq4jSIDgCBJE0B0kjUJPkACbRJAgAvvRVh0sp69X\n3Y5HW8AmESSIwA6SnCnojbuGKV+gT2krECRAcAQJInAESe7v61YW/I6AabHvMKa0tbchSIBgCBJE\n4A6S7rsKsdzoLPxT2uYIEiA4ggQA4IUgAQB4IUgAAF4IEmzO2/u7czmAdRAk2ByCBEgLQYLNIUiA\ntBAk2ByCBEgLQYLNIUiAtBAk2ByCBEgLQYLNIUiAtBAk2ByCBEgLQYLNIUiAtBAk2ByCBEgLQYLN\nIUiAtBAk2ByCBEgLQYLNIUiAtBAk2ByCBEgLQQIA8EKQAAC8ECQAAC8ECRLym13O1+zt/ZpdfuTy\nV/b5kS8/37Nvq52tuR2AGAgSJEQExMcj+6uWjw+St/Mt+3ya7QDEQJAgIc2AOH299PKOIGmEzb/s\n+2pvByAGggQJ0QGRB8ZFhUIVHAQJkDKCBAmpg+T7+chO+b/LUODRFpAyggQJE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nuRzbQJAAWNEz+7yds9PDBMnavzC51G/5L+j3mr1dr9m3a10kBAmAFREk3ggSAMdVhkjx+/nVb+jr\nIHl8Zaf8v+U6u7Bb292+sr/Gfn1YQfKS/SiZkKt++1/Kx/B9z9sXYzH71G2tZfOVc1QeM+/rww6S\nofkZ2n46ggTAitx3JLKwFYW5KoZ2e12kg4WJDJKyL/LuqOiLq+gWgaO3a90hlH0Oc5c1NF86RERo\nNeevbF9tXwUlQQJgs9yFsVF0ZWF2PsYJWahlkDj0HL9zDEWx9ivUFdfx5TLnsUR/VFsrdMs7K7/+\nESQAVjQtSJyPk7R6Hz5cQVL2qT5Ws+i67ojk462Qj7Wcd18yPBxBIefY2RdXOE1EkABY0YwgaRXK\nkGSQ1AFS9c8uuvrRUOtuqCruIe+WCBIAcJgWJCGKXj8RJK6i3Dh+2Xf33YYOkOKPBgL21zV+uYxH\nWwCOZ2KQmOIti2Gxvud7jUmsIJEFVt99mGMNFeBy/Xuwx1olO7zK+WrNjzhm/x8r2NvPQ5AAWFWz\n4A4FiaKLZfWdRagQUUSQ5K/Lv9Iyx1F9MP2z+1CrinTXYy9v8th5X0P8+W+rzTQECQAswfmYKUGO\nx11TESQAsAB1p1U/QkpE6zGg/ahrHoIEAEIy36V4fspfSvUoUQsRdgQJAMALQQIA8EKQAAC8ECQA\nAC8ECQDAC0ECAPBCkAAAvBAkAAAvBAkAwMO/7D/eyWnvXN/H0gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.core.display import Image\n",
    "\n",
    "Image('tree.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Math Basics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Vectors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## vectors\n",
    "\n",
    "x = [1, 2, 3, 4, 5]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5]\n",
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "# using numpy\n",
    "import numpy as np\n",
    "x = np.array([1, 2, 3, 4, 5])\n",
    "\n",
    "print(x)\n",
    "print(type(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matrices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 5 2]\n",
      " [4 7 4]\n",
      " [2 0 9]]\n",
      "(3, 3)\n"
     ]
    }
   ],
   "source": [
    "## matrices\n",
    "\n",
    "m = np.array([[1, 5, 2],\n",
    "              [4, 7, 4],\n",
    "              [2, 0, 9]])\n",
    "\n",
    "# view matrix\n",
    "print(m)\n",
    "\n",
    "# view dimensions\n",
    "print(m.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matrix transpose"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matrix Transpose:\n",
      " [[1 4 2]\n",
      " [5 7 0]\n",
      " [2 4 9]] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# matrix transpose\n",
    "print('Matrix Transpose:\\n', m.transpose(), '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matrix determinant"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matrix Determinant: -105.0 \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# matrix determinant\n",
    "print ('Matrix Determinant:', np.linalg.det(m), '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Matrix inverse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matrix inverse:\n",
      " [[-0.6         0.42857143 -0.05714286]\n",
      " [ 0.26666667 -0.04761905 -0.03809524]\n",
      " [ 0.13333333 -0.0952381   0.12380952]] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# matrix inverse\n",
    "m_inv = np.linalg.inv(m)\n",
    "print ('Matrix inverse:\\n', m_inv, '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Identity matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Product of matrix and its inverse:\n",
      " [[ 1.  0.  0.]\n",
      " [ 0.  1.  0.]\n",
      " [ 0.  0.  1.]]\n"
     ]
    }
   ],
   "source": [
    "# identity matrix (result of matrix x matrix_inverse)\n",
    "iden_m =  np.dot(m, m_inv)\n",
    "iden_m = np.round(np.abs(iden_m), 0)\n",
    "print ('Product of matrix and its inverse:\\n', iden_m)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Eigendecomposition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Eigen Values: [ -1.32455532  11.32455532   7.        ] \n",
      "\n",
      "Eigen Vectors:\n",
      " [[-0.91761521  0.46120352 -0.46829291]\n",
      " [ 0.35550789  0.79362022 -0.74926865]\n",
      " [ 0.17775394  0.39681011  0.46829291]]\n"
     ]
    }
   ],
   "source": [
    "# eigendecomposition\n",
    "m = np.array([[1, 5, 2],\n",
    "              [4, 7, 4],\n",
    "              [2, 0, 9]])\n",
    "\n",
    "eigen_vals, eigen_vecs = np.linalg.eig(m)\n",
    "\n",
    "print('Eigen Values:', eigen_vals, '\\n')\n",
    "print('Eigen Vectors:\\n', eigen_vecs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SVD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Getting SVD outputs:-\n",
      "\n",
      "U:\n",
      " [[ 0.3831556  -0.39279153  0.83600634]\n",
      " [ 0.68811254 -0.48239977 -0.54202545]\n",
      " [ 0.61619228  0.78294653  0.0854506 ]] \n",
      "\n",
      "S:\n",
      " [ 12.10668383   6.91783499   1.25370079] \n",
      "\n",
      "VT:\n",
      " [[ 0.36079164  0.55610321  0.74871798]\n",
      " [-0.10935467 -0.7720271   0.62611158]\n",
      " [-0.92621323  0.30777163  0.21772844]] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# SVD\n",
    "m = np.array([[1, 5, 2],\n",
    "              [4, 7, 4],\n",
    "              [2, 0, 9]])\n",
    "\n",
    "U, S, VT = np.linalg.svd(m)\n",
    "\n",
    "print ('Getting SVD outputs:-\\n')\n",
    "print('U:\\n', U, '\\n')\n",
    "print('S:\\n', S, '\\n')\n",
    "print('VT:\\n', VT, '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Descriptive Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data:  [ 6 13  3  8 16 14 15  6 11 16 16  9  2 18  1]\n"
     ]
    }
   ],
   "source": [
    "# descriptive statistics\n",
    "import scipy as sp\n",
    "import numpy as np\n",
    "\n",
    "# get data\n",
    "nums = np.random.randint(1,20, size=(1,15))[0]\n",
    "print('Data: ', nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean: 10.2666666667\n",
      "Median: 11.0\n",
      "Mode: ModeResult(mode=array([16]), count=array([3]))\n",
      "Standard Deviation: 5.495048276\n",
      "Variance: 30.1955555556\n",
      "Skew: -0.283914098226024\n",
      "Kurtosis: -1.3113890167335824\n"
     ]
    }
   ],
   "source": [
    "# get descriptive stats\n",
    "print ('Mean:', sp.mean(nums))\n",
    "print ('Median:', sp.median(nums))\n",
    "print ('Mode:', sp.stats.mode(nums))\n",
    "print ('Standard Deviation:', sp.std(nums))\n",
    "print ('Variance:', sp.var(nums))\n",
    "print ('Skew:', sp.stats.skew(nums))\n",
    "print ('Kurtosis:', sp.stats.kurtosis(nums))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
